package com.smart.dao;
 
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.smart.model.UserToken;
import com.smart.model.UserTokenCond;
import com.smart.model.VerifyCode;

/**
 * 
 * @author Sunxin
 *
 */
 
@Repository
public class UserTokenDaoImpl extends BaseEntityDao<UserToken, UserTokenCond, Long> implements UserTokenDao{

	@Override
	public UserToken findLatestToken(Long uid) {
		Criteria crit = this.getSession().createCriteria(UserToken.class);
		crit.add(Restrictions.eq("uid", uid));
		crit.addOrder(Order.desc("timeCreated"));
		crit.setMaxResults(1);
		List<UserToken> list = super.find(crit);
		if(!list.isEmpty()) {
			return list.get(0);
		}else {
			return null;
		}
	}

}
